<?php
get_header();
?>
	<section class="main">
		<nav class="main-nav">
			<ul>						
				<?php 
					$taxonomies = 'building-type';
					$args  = array('hide_empty'=>false);
					$terms = get_terms( $taxonomies, $args ) ;
					foreach($terms as $term){							
						if( $term->parent == 0 && get_tax_meta($term->term_id,'building_tax_show_home') == 1){
							?>
						<li <?php echo checkActiveMenuHome($term->term_id)?>><a href="<?php echo get_term_link($term,$taxonomies);?>"><?php echo $term->name;?></a></li>
						<li class="line-nav"></li>
					<?php
						}
					}
				?>
				<?php $pageid = 58 ;if(ICL_LANGUAGE_CODE == 'vi') $pageid = 76 ;?>
			   <li><a href="<?php echo get_page_link($pageid)?>">
					<?php echo get_page($pageid)->post_title; ?>
				</a></li>
			</ul>
		</nav>
    	<?php get_sidebar(); ?>        
        <!-- main content -->
        <section class="main-content">
        	
			<section class="discrumble">
				<?php if(function_exists('bcn_display')){ bcn_display();}?>
			</section>			
			<section class="col-main">
				<article class="detail">
					<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
						
						<h1 class="detail-title"><?php the_title();?></h1>	
						<div class="detail-images" style="display:none">
							<!---->
							<div class="slider-wrapper theme-default">
								<div id="slider2" class="nivoSlider">
									<?php
										echo GetListImage(get_the_ID(),'building_imgadv');
									?>              
								</div>
							</div>
						  <!---->
						</div>
						<div class="detail-cont">
							<div class="total-des">
								<p>
									<strong><?php _e('Price:','building')?></strong>
									<?php
										$currency = get_post_meta(get_the_ID() , 'building_currency' , true);
										$arr_currency = explode('/',$currency);
										$extra = '';
										$isForSale = get_post_meta(get_the_ID() ,'building_type', false);
										foreach( $isForSale as $items){
											if( $items == 'For Rent'){
												$extra = '/'.$arr_currency[1];
											}
										}
									?>									
										
									<span class="price-det">$<?php echo number_format( get_post_meta(get_the_ID() , 'building_cost' , true), 2) ;?></span>									
								</p>
								
								<div class="total-des-col">
									<p>
										<strong><?php _e('Interior:','building')?></strong>
										<?php echo rwmb_meta('building_interior');?>										
									</p>
									<p>
										<strong><?php _e('Type:','building')?></strong>
										<?php echo get_the_term_list( $post->ID, 'building-type', '', ', ', '' ); ?>
									</p>
									<p>
										<strong><?php _e('Room:','building')?></strong>
										<?php echo rwmb_meta('building_num_room');?>										
									</p>
									<p>
										<strong><?php _e('BedRoom:','building')?></strong>
										<?php echo rwmb_meta('building_num_bedroom');?>										
									</p>
								</div>
								<div class="total-des-col">
									<p>
										<strong><?php _e('Code:','building')?></strong>
										<?php echo rwmb_meta('building_code');?>										
									</p>
									<p>
										<?php
											if(ICL_LANGUAGE_CODE == 'vi'){
												$action_url = get_bloginfo('url').'building/';
											}else{
												$action_url = get_bloginfo('url').'/building/';
											}
										?>
										<strong><?php _e('Location:','building')?></strong>
										<?php echo rwmb_meta('building_street');?>,
										<?php echo rwmb_meta('building_address');?>,										
										<a href="<?php echo $action_url?>?s=+&location=<?php echo rwmb_meta('building_district');?>">
											<?php echo rwmb_meta('building_district');?>
										</a>
									</p>
									<p>
										<strong><?php _e('Level:','building')?></strong>
										<?php echo rwmb_meta('building_level');?>												
									</p>
									<p>
										<strong><?php _e('Land Area:','building')?></strong>
										<?php echo rwmb_meta('building_land_area');?>sqm										
									</p>
									<p>
										<strong><?php _e('Level:','building')?></strong>
										<?php echo rwmb_meta('building_allow_test');?>										
									</p>
								</div>
								<div class="clear"></div>
							</div>
							<div class="description">
								<h3 class="des-title"><?php _e('Description:','building')?></h3>
									<?php the_content();?>
								<div class="clear"></div>
								<h3 class="des-title"><?php _e('Amenities:','building')?></h3>
									<!-- 
		                             <tr>
		                    			<td width="30%"><img src="images/tick.png">Internet</td>
		                                <td width="30%"><img src="images/tick.png"> Parking</td>
		                                <td width="30%"><img src="images/tick.png">Cable Television</td>
		               				 </tr>
		               				  -->
                            		<table width="100%" border="0" cellspacing="0" cellpadding="0" class="table-des">
                             		 <tbody>
									<?php 
										$building_extra_infomation = explode("\n", rwmb_meta('building_extra_infomation'));
										for ($i=0;$i<count($building_extra_infomation);$i+=3){
											echo "<tr>";
											for($j=$i;$j<$i+3; $j++) {
												if ($building_extra_infomation[$j]){
												echo "<td width='30%'><img src='/wp-content/themes/hotel/images/tick.png'>".strip_tags($building_extra_infomation[$j])."</td>";
												}
											}
											echo "</tr>";
										}		
									?>
									</tbody></table>											
								<div class="clear"></div>
								<h3 class="des-title"><?php _e('Map:','building')?></h3>
								<?php
									$args_maps = array(
										'type'         => 'map',
										'width'        => 707, 
										'height'       => 340, 
										'zoom'         => 14,  
										'marker'       => true,
										'marker_title' => '',
										'info_window'  => get_the_title(), // Info window content, can be anything. HTML allowed.
									);
									echo rwmb_meta( 'building_map', $args_maps ); 
								?>
								<div class="clear"></div>
							</div>
							<div class="detail-send">	
								<?php $user = get_user_by( 'id' , $post->post_author ); ?>
								<div class="send-left">
									<h3 class="des-title"><?php _e('Send Enquiry','building')?></h3>
									<div class="form-send">
										<?php echo do_shortcode('[contact-form-7 id="69" title="Contact Agent"]');?>
										<?php
											$emailTo = $user->user_email;
										?>
										<script type="text/javascript">
											jQuery(document).ready(function($){
												$('.wpcf7-form #emailTo').attr('value','<?php echo $emailTo;?>')
											})
										</script>
									</div>
								</div>
								<div class="send-right">
									<h3 class="des-title"><?php _e('Agent','building')?></h3>
									<div class="form-send">
										<p><strong><?php echo $user->user_nicename?></strong></p>
										<p class="frm-img">
											<?php if($user->image == ''):
												echo get_avatar( get_the_author_meta( $user->ID ), 190 );
											?>	
											<?php else: ?>
												<img alt="<?php echo $user->user_nicename?>" src="<?php echo $user->image?>" style="max-width: 100%;">
											<?php endif;?>
										</p>
										<p>
											<strong><?php _e('Company:','building')?></strong>
											<a href="<?php echo $curauth->user_url;?>"><?php echo $curauth->company;?></a>
										</p>
										<p>
											<strong><?php _e('Mobile:','building')?></strong>
											<?php echo $user->mobile;?>
										</p>
									</div>
									<style>
										.form-send .frm-img .avatar {height: 158px;}
									</style>
								</div>
								<div class="clear"></div>
							</div>
							<?php $term_list = wp_get_post_terms($post->ID, 'building-type', array("fields" => "ids"));?>	
							<div id="comments_template" style="display:none">
								<?php comments_template(); ?>
							</div>
						</div>
					<?php endwhile; ?>
					<?php wp_reset_query();?>	
					<div class="related-real">
						<h3 class="des-title">More <?php echo get_term( $term_list[0], 'building-type')->name?></h3>
						<?php  echo do_shortcode('[building_categories exclude="'.$post->ID.'" per_page="9" ids="'.implode(',',$term_list).'"]');?>
						<div class="clear"></div>
					</div>
					<div id="comments_new" class="comment">
						<h3 class="des-title">Comment</h3>				
						<script type="text/javascript">
							jQuery(document).ready(function(){
								$('#comments_template').appendTo(jQuery('#comments_new'));
								//$('#comments_template').removeAttr('style');
							})
						</script>
					</div>		
					<br/><br/><br/>
				</article>
			</section>
        </section>
        <!-- end main content -->
        <div class="clear"></div>
    </section>
    <!-- content -->
<script type="text/javascript">
var numItems = jQuery(".detail-images img").length;
var cyclerLoaded = false;
var numberOfPreloaded = 0;
function setStyleSlideshow(){
	jQuery('.detail-images').css('display','block');
	jQuery('#slider2').nivoSlider({
		controlNavThumbs: true
		}
	);
}
function imageLoaded(){      
	numberOfPreloaded++;
	  if (numberOfPreloaded == numItems && !cyclerLoaded){							
			cyclerLoaded = true;
			setStyleSlideshow();
		}
}
jQuery(document).ready(function($){
	$('.detail-images img').each(function(){							
		var image = new Image();
		image.src = $(this).attr('src');
		if (image.complete)        
		  imageLoaded();        
		else        
		  image.onload = imageLoaded;
	});
	setStyleSlideshow();
})
</script>	
<?php get_footer(); ?>